Let the help command work consistently everywhere
authorJake Kerr <kodafox@gmail.com>
Sun, 5 Oct 2014 07:13:43 +0000 (16:13 +0900)
committerJake Kerr <kodafox@gmail.com>
Sun, 5 Oct 2014 07:15:42 +0000 (16:15 +0900)
This adds a dummy help command so that it's usage can be documented with docopt!

Also adds help flags to all of the subcommands that were missing them. Without
that `cargo help sub-command` shows Invalid Argument before the usage text.

src/bin/cargo.rs
src/bin/config_for_key.rs
src/bin/config_list.rs
src/bin/git_checkout.rs
src/bin/help.rs [new file with mode: 0644]
src/bin/locate_project.rs
src/bin/read_manifest.rs
src/bin/verify_project.rs

index 09c2ec2072e160f9fe1ff6f7a53a1a3f6860f4d8..4f52d482d963c2f879457e3b5ea595f900c82cd0 100644 (file)
@@ -58,6 +58,7 @@ macro_rules! each_subcommand( ($macro:ident) => ({
     $macro!(fetch)
     $macro!(generate_lockfile)
     $macro!(git_checkout)
+    $macro!(help)
     $macro!(locate_project)
     $macro!(login)
     $macro!(new)
index 2b3614787769225b57c3f664e63c9db62890be13..f73f5bd6d3226af341e43f279a9aa974dcfad009 100644 (file)
@@ -11,7 +11,12 @@ struct ConfigOut {
 }
 
 docopt!(ConfigForKeyFlags, "
-Usage: cargo config-for-key --human --key=<key>
+Usage:
+    cargo config-for-key --human --key=<key>
+    cargo config-for-key -h | --help
+
+Options:
+    -h, --help          Print this message
 ")
 
 pub fn execute(args: ConfigForKeyFlags,
index 2fd50b7f4afdf76004328512cbefbf1c29a3891f..eb4254ad52767a965681c26bbf062155e5f3ca38 100644 (file)
@@ -11,7 +11,12 @@ struct ConfigOut {
 }
 
 docopt!(ConfigListFlags, "
-Usage: cargo config-list --human
+Usage:
+    cargo config-list --human
+    cargo config-list -h | --help
+
+Options:
+    -h, --help          Print this message
 ")
 
 pub fn execute(args: ConfigListFlags,
index 40299849488e2524cb927e54a66b4e3219433d02..703463711c884d7e5e6f9ae35adb2fab4f635221 100644 (file)
@@ -8,6 +8,7 @@ use cargo::util::{Config, CliResult, CliError, human, ToUrl};
 docopt!(Options, "
 Usage:
     cargo git-checkout [options] --url=URL --reference=REF
+    cargo git-checkout -h | --help
 
 Options:
     -h, --help              Print this message
diff --git a/src/bin/help.rs b/src/bin/help.rs
new file mode 100644 (file)
index 0000000..8c9d989
--- /dev/null
@@ -0,0 +1,22 @@
+use docopt;
+
+use cargo::core::MultiShell;
+use cargo::util::{CliResult, CliError};
+
+docopt!(Options, "
+Get some help with a cargo command.
+
+Usage:
+    cargo help <command>
+    cargo help -h | --help
+
+Options:
+    -h, --help          Print this message
+")
+
+pub fn execute(_: Options, _: &mut MultiShell) -> CliResult<Option<()>> {
+    // This is a dummy command just so that `cargo help help` works.
+    // The actual delegation of help flag to subcommands is handled by the
+    // cargo command.
+    Err(CliError::new("Help command should not be executed directly.", 101))
+}
index db1500525da85f2aa80ca535e8aeec70f49cfda1..812b8530e4161d89c6901da201381b70b515025d 100644 (file)
@@ -10,6 +10,7 @@ Usage:
 
 Options:
     --manifest-path PATH    Path to the manifest to build benchmarks for
+    -h, --help              Print this message
 ", flag_manifest_path: Option<String>)
 
 #[deriving(Encodable)]
index cd7e84e5c3037b33c82bf3c52c2df4969943fd67..686c1a5b2bec64a33362633482e4f50ad59acfeb 100644 (file)
@@ -6,7 +6,8 @@ use cargo::sources::{PathSource};
 
 docopt!(Options, "
 Usage:
-    cargo clean [options] --manifest-path=PATH
+    cargo read-manifest [options] --manifest-path=PATH
+    cargo read-manifest -h | --help
 
 Options:
     -h, --help              Print this message
index 21f8222f6b755a96dbe0e66b28bb12ab096bb5b5..72358d48f432a806a430468083ea4f7f3830ff0f 100644 (file)
@@ -13,6 +13,7 @@ pub type Error = HashMap<String, String>;
 docopt!(Flags, "
 Usage:
     cargo verify-project [options] --manifest-path PATH
+    cargo verify-project -h | --help
 
 Options:
     -h, --help              Print this message